package com.mall.equipment.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.mall.equipment.entity.BaseResponse;
import com.mall.equipment.entity.ImgBackEntity;
import com.mall.equipment.entity.Person;
import com.mall.equipment.service.EquipmentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *海思设备
 */
@RestController
@RequestMapping("/equipment")
public class EquipmentController {

    @Resource
    public EquipmentService equipmentService;

    @PostMapping("/setTime")
    public BaseResponse setTime(){
        return BaseResponse.ok(equipmentService.setTime());
    }

    @PostMapping("/setMaskConfig")
    public BaseResponse setMaskConfig(int isMaskOpen){
        return BaseResponse.ok(equipmentService.setMaskConfig(isMaskOpen));
    }

//===================================配置类↑================================

    @PostMapping("/save")
    public BaseResponse save(Person person){
        equipmentService.createPerson(person);
        return BaseResponse.ok();
    }

    @PostMapping("/update")
    public BaseResponse update(Person person){
        equipmentService.updatePerson(person);
        return BaseResponse.ok();
    }

    @PostMapping("/del")
    public BaseResponse del(String id){
        return BaseResponse.ok(equipmentService.delPerson(id));
    }

    @PostMapping("/find")
    public BaseResponse<List<Person>> find(){
        return BaseResponse.ok(equipmentService.find());
    }

    @PostMapping("/createPasstime")
    public BaseResponse update(String personId,String time){
        return BaseResponse.ok(equipmentService.createPasstime(personId,time));
    }

    @PostMapping("/deletePasstime")
    public BaseResponse update(String id){
        return BaseResponse.ok(equipmentService.deletePasstime(id));
    }

    @PostMapping("/createImg")
    public BaseResponse createImg(String id){
        return BaseResponse.ok(equipmentService.createImg(id));
    }

    @PostMapping("/deleteImg")
    public BaseResponse deleteImg(String id){
        return BaseResponse.ok(equipmentService.deleteImg(id));
    }

    @PostMapping("/setCallBack")
    public BaseResponse setCallBack(){
        return BaseResponse.ok(equipmentService.setIdentifyCallBack());
    }

    @PostMapping("/callBack")
    public BaseResponse callBack(){
        return BaseResponse.ok(equipmentService.callBack());
    }

    @PostMapping("/delRecords")
    public BaseResponse delRecords(String id){
        return BaseResponse.ok(equipmentService.deleteRecords(id));
    }

    @PostMapping("/selectRecords")
    public BaseResponse selectRecords(){
        return BaseResponse.ok(equipmentService.newFindRecords());
    }

    @RequestMapping("/back")
    public String rollBack(ImgBackEntity c){
        Map<String,Object> map = new HashMap<>();
        map.put("result",1);
        map.put("success",true);
        System.out.println(DateUtil.formatDateTime(new Date())+":"+JSONUtil.toJsonStr(c));
        return JSONUtil.toJsonStr(map);
    }

    @PostMapping("/test")
    public BaseResponse test(){
        return BaseResponse.ok(equipmentService.getDeviceKey());
    }

}
